package com.yakami.ocean.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jakewharton.rxbinding.view.RxView;
import com.yakami.ocean.R;
import com.yakami.ocean.view.fragment.base.BaseFragment;

import java.util.concurrent.TimeUnit;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author Yakami, Created on 2016/4/22
 */
public class TestResultFragment extends BaseFragment {

    @Bind(R.id.score) TextView mScore;
    @Bind(R.id.right_time) TextView mRightTime;
    @Bind(R.id.wrong_time) TextView mWrongTime;
    @Bind(R.id.accuracy) TextView mAccuracy;
    @Bind(R.id.back_to_home) TextView mHome;
    private String mScoreStr;
    private String mRightTimeStr;
    private String mWrongTimeStr;
    private String mAccuracyStr;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceBundle) {
        View view = inflater.inflate(R.layout.fragment_test_result, container, false);
        ButterKnife.bind(this, view);

        mScore.setText(mScoreStr);
        mRightTime.setText(mRightTimeStr);
        mWrongTime.setText(mWrongTimeStr);
        mAccuracy.setText(mAccuracyStr);

        RxView.clicks(mHome)
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribe((Void) -> {
                    getActivity().finish();
                });
        return view;
    }

    public void setData(String score, String rightTime, String wrongTime, String accuracy) {
        mScoreStr = score;
        mRightTimeStr = rightTime;
        mWrongTimeStr = wrongTime;
        mAccuracyStr = accuracy;
    }
}
